package cn.elves.model.draw.service.algorithm;

import cn.elves.model.activity.entity.po.UserTakeActivity;
import cn.elves.model.draw.service.algorithm.impl.ProbabilisticFixedDrawAlgorithm;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 精灵
 * @time 2024-06-19   11:38
 */

public class DrawInstanceHolder {

    @Resource
    private ProbabilisticFixedDrawAlgorithm probabilisticFixedDrawAlgorithm;
    @Resource
    private cn.elves.model.draw.service.algorithm.impl.QuantityFixedDrawAlgorithm quantityFixedDrawAlgorithm;
    @Resource
    private cn.elves.model.draw.service.algorithm.guarantee.impl.ProbabilisticGuaranteeFixedDrawAlgorithm probabilisticGuaranteeFixedDrawAlgorithm;

    @Resource
    private Map<String, DrawAlgorithm> configMap = new ConcurrentHashMap<>();

    @PostConstruct
    public void init() {
        configMap.put("probabilisticFixed", probabilisticFixedDrawAlgorithm);
        configMap.put("quantityFixed", quantityFixedDrawAlgorithm);
        configMap.put("probabilisticGuaranteeFixed", probabilisticGuaranteeFixedDrawAlgorithm);
    }


    public String selectDrawStrategyToDraw(UserTakeActivity userTakeActivity) {
        DrawAlgorithm drawAlgorithm = configMap.get(null);
        DrawContextHolder.set(new DrawParam());//可从db选取
        drawAlgorithm.prepare(null,null,null,null);
        String awardId = drawAlgorithm.randomDraw(null, null);
        DrawContextHolder.clear();
        return awardId;
    }

}
